package com.gxuwz.Market.business.action.web;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.Market.business.entity.ServiceAcademy;
import com.gxuwz.Market.business.service.IServiceAcademyService;
import com.gxuwz.core.pagination.Result;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class ServiceAcademyAction extends BaseAction implements Preparable, ModelDriven<ServiceAcademy> {

	protected static final String LIST_JSP = "/WEB-INF/page/web/ServiceAcademy_list.jsp";  
	protected static final String ADD_JSP = "/WEB-INF/page/web/ServiceAcademy_add.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/web/ServiceAcademy_edit.jsp";
	
	@Autowired
	private IServiceAcademyService serviceAcademyService;
	private List<ServiceAcademy> academyList;
	private ServiceAcademy serviceAcademy;
	private Result<ServiceAcademy> pageResult;
	
	
	
	@Override
	public void prepare() throws Exception {
		if(null == serviceAcademy){
			serviceAcademy = new ServiceAcademy();
		}
	}

	@Override
	public ServiceAcademy getModel() {
		return serviceAcademy;
	}
	
	@Override
	public String execute() throws Exception {
		
		return SUCCESS;
	}
	
	/**
	 * 打开列表页面
	 * @return
	 */
	public String openList(){
		pageResult = serviceAcademyService.find(serviceAcademy, getPage(), getRow());
		setForwardView(LIST_JSP);
		return SUCCESS;
	}

	
	/**
	 * 删除
	 * @return
	 */
	public String delete() {
		serviceAcademyService.delete(serviceAcademy.getId());
		serviceAcademy.setId(null);
		return openList();
	}

	/**
	 * 打开修改页面
	 * @return
	 */
	public String openEdit(){
		serviceAcademy = serviceAcademyService.findById(serviceAcademy.getId());
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}

	public String openAdd() {
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	
	public String add() {
		if(null != serviceAcademy){
			serviceAcademyService.add(serviceAcademy);
		}
		Integer i = serviceAcademyService.findByProperty("academyId", serviceAcademy.getAcademyId()).get(0).getId();
		serviceAcademy =new ServiceAcademy();
		return openList();
	}
	
	public String edit(){
		if(null != serviceAcademy){
			serviceAcademyService.update(serviceAcademy);
		}
		serviceAcademy =new ServiceAcademy();
		return openList();
	}
	
	public ServiceAcademy getServiceAcademy() {
		return serviceAcademy;
	}

	public void setServiceAcademy(ServiceAcademy serviceAcademy) {
		this.serviceAcademy = serviceAcademy;
	}

	public Result<ServiceAcademy> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<ServiceAcademy> pageResult) {
		this.pageResult = pageResult;
	}

	public List<ServiceAcademy> getAcademyList() {
		return academyList;
	}

	public void setAcademyList(List<ServiceAcademy> academyList) {
		this.academyList = academyList;
	}







	
	
	
}
